<?php
/* SVN FILE: $Id: races_controller.php 250 2010-06-17 10:55:41Z gregory.rome $ */
/**
 * Races Controller.
 *
 * Available races.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009-2010, Grégory Romé.
 * @link          http://code.google.com/p/cbbweb/ cBBweb Project
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 * @version       $Revision: 250 $
 * @modifiedby    $LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-06-17 10:55:41 +0000 (Thu, 17 Jun 2010) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Races Controller.
 *
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 */
class RacesController extends AppController {

	var $name = 'Races';

    function index() {
    	$this->Race->recursive = 1;
        $races = $this->paginate('Race');
        if (isset($this->params['requested'])) {
            return $races;
        } else {
            $this->set('races', $races);
        }
    }

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Race.', true));
			$this->redirect(array('action'=>'index'));
		}

		$race = $this->Race->find('first',
			array('conditions' => array('Race.ID' => $id)));

		$this->Race->Team->recursive = 2;
		$teams = $this->paginate('Team', array('Team.idRaces'=>$id));

        if (isset($this->params['requested'])) {
            return $race;
        } else {
        	$this->set('race', $race);
            $this->set('teams', $teams);
        }
	}

}
?>
